import {createSlice} from "@reduxjs/toolkit"
// 1.createSlice 创建reducer 的切片
const userSlice = createSlice(
    {
        //用来生成action的type
        name: 'user',
        initialState: {
            name: "张三",
            age: 18,
        },
        //指定state的各种操作，直接在对象中添加方法
        reducers: {
            setName (state, action) {
                state.name = action.payload
            }
        }
    })
export const {setName} = userSlice.actions
export const userReducer = userSlice.reducer